package cn.newtest.common.dbutils.handlers;

/**
 * 
 * 用于替代RowResult2BeanReader,一个RowMapper的实现
 * @author WangChui(baiyibing@gmail.com)
 * @version 1.0 TODO
 * 
 */
import java.sql.ResultSet;
import java.sql.SQLException;

import org.apache.commons.dbutils.BasicRowProcessor;
import org.apache.commons.dbutils.RowProcessor;
import org.springframework.jdbc.core.RowMapper;

public class MultiColumnRowMapper implements RowMapper {

	/**
	 * The Class of beans produced by this handler.
	 */
	private Class type = null;

	/**
	 * The RowProcessor implementation to use when converting rows into beans.
	 */
	private RowProcessor rowProcessor = BasicRowProcessor.instance();

	public MultiColumnRowMapper(Class type, RowProcessor rowProcessor) {
		this.type = type;
		this.rowProcessor = rowProcessor;
	}

	public Object mapRow(ResultSet rs, int rowNum) throws SQLException {
		return this.rowProcessor.toBean(rs, this.type);
	}

	public RowProcessor getRowProcessor() {
		return rowProcessor;
	}

	public void setRowProcessor(RowProcessor rowProcessor) {
		this.rowProcessor = rowProcessor;
	}

	public Class getType() {
		return type;
	}

	public void setType(Class type) {
		this.type = type;
	}

}
